<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;


class Base extends Model
{
    use HasFactory,SoftDeletes;

    protected $guarded = [];


    public function treeLevel($data, $pid = 0, $html = '--', $level = 0)
    {
        static $arr = [];

        foreach ($data as $key => $val) {
            if ($val['pid'] == $pid) {
                $val['html'] = str_repeat($html, $level * 2);

                $val['level'] = $level + 1;

                $arr[] = $val;

                $this->treeLevel($data, $val['id'], $html, $val['level']);
            }
        }

        return $arr;
    }

}
